﻿using IterationLife.Domains.Sports.Models;
using Util.Datas.Ef;

namespace IterationLife.Datas.Mappings.Sports {
    /// <summary>
    /// 体育比赛分组运动员映射配置
    /// </summary>
    public class SportEventGroupPersonMap : AggregateRootMapBase<SportEventGroupPerson> {
        /// <summary>
        /// 映射表
        /// </summary>
        protected override void MapTable() {
            ToTable( "SportEventGroupPersons", "Sports" );
        }
        
        /// <summary>
        /// 映射属性
        /// </summary>
        protected override void MapProperties() {
            //体育比赛分组运动员编号
            Property(t => t.Id)
                .HasColumnName("SportEventGroupPersonId");
        }
        
        /// <summary>
        /// 映射导航属性
        /// </summary>
        protected override void MapAssociations() {
            //运动员
            HasOptional(t => t.SportAthlete)
                .WithMany(t => t.SportEventGroupPeople)
                .HasForeignKey(d => d.SportAthleteId);
            //用户
            HasOptional(t => t.SportUser)
                .WithMany()
                .HasForeignKey(d => d.SportAthleteId);
            //体育比赛分组
            HasOptional(t => t.SportEventGroup)
                .WithMany(t => t.SportEventGroupPeople)
                .HasForeignKey(d => d.SportEventGroupId);
        }
    }
}
